Back to Editorials CodeCraft β
  • Github
  • Instagram
< >

Amazing Year

TIME LIMIT = 1 SEC.

  • We'll call a year an 'Amazing Year' if all the digits of that year are unique. Ex. 2019.Now, given a year as your input, print the past amazing year and the future amazing year for that input.
Input Output
First line will contain the input year. Print two space-separated years - the past amazing year and the future amazing year to the input.
Constraints
  • 123 ≤ Year ≤ 9876
Example Test Case
Input             Output
2014 2013  2015
Solution

#include <iostream> using namespace std; bool isUnique(int year) { short a,b,c,d; //digits of the year d = year % 10; //fourth digit b = (year/10) %10; //third digit c = (year/100) %10; //second digit a = (year/1000) %10; //first digit if(a!=b && a!=c && a!=d && b!=c && b!=d && c!=d) //if none of the digits are equal return true; //return true else return false; //else return false } int main() { int year,past,future; cin>>year; //current year past = year-1,future=year+1; while(1) { if(isUnique(past) && isUnique(future)) break; if(!isUnique(past)) //check all previous years past--; if(!isUnique(future))//check all future years future++; } cout<<past<<" "<<future; //print result. return 0; }
  • #1 Thieves
  • #2 The Queue of Doubts
  • #3 Summation of Primes
  • #4 Spacious Maximus
  • #5 Samosas
  • #6 Reasonably Sound
  • #7 Product of Digits
  • #8 Prime Usernames
  • #9 Path Shifter
  • #10 Keypad Count
  • #11 Even Vowels
  • #12 Encryption
  • #13 Decryption
  • #14 Canteen Accountant
  • #15 Attendance Register
  • #16 Amazing Year

Get in touch

  • executives@codingstudio.club
  • +91 9010342360
  • Vignana Bharthi Instute of Technology
    Aushapur, Ghatkesar, Hyderabad, Telengana - India

© coding.Studio();